﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using MediaCentral.Services.DAL;
using MediaCentral.Services.DAL.Entities;
using System.ServiceModel.Activation;

namespace MediaCentral.Services
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    // TODO: Take the list names out to AppSettings in the web.config or something
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
    public class MCService : IMCService
    {
        public List<Video> GetAllVideos()
        {
            List<Video> vids = new List<Video>();
            vids.AddRange(SharePoint.GetVideosByTag("LocalVideos", string.Empty, Int32.MaxValue));
            vids.AddRange(SharePoint.GetVideosByTag("YouTubeVideos", string.Empty, Int32.MaxValue));

            return vids;
        }

        public List<Video> GetNumberOfVideos(int num)
        {
            List<Video> vids = new List<Video>();
            vids.AddRange(SharePoint.GetVideosByTag("LocalVideos", string.Empty, num));
            vids.AddRange(SharePoint.GetVideosByTag("YouTubeVideos", string.Empty, num));
            return vids;
        }

        public List<Video> GetAllVideosByTag(string tag)
        {
            List<Video> vids = new List<Video>();
            vids.AddRange(SharePoint.GetVideosByTag("LocalVideos", tag, Int32.MinValue));
            vids.AddRange(SharePoint.GetVideosByTag("YouTubeVideos", tag, Int32.MinValue));

            return vids;
        }

        public string[] GetAllTags()
        {
            return SharePoint.GetAllTags();
        }

        public bool UpdateVideo(string libName, int id, string title, string description, string thumbnail, string tags)
        {
            return SharePoint.UpdateVideo(libName, id, title, description, thumbnail, tags);
        }

        public List<Video> GetVideosBySearchString(string query)
        {
            List<Video> videos = new List<Video>();
            videos.AddRange(SharePoint.SearchVideos("LocalVideos", query));
            videos.AddRange(SharePoint.SearchVideos("YouTubeVideos", query));
            return videos;
        }

        public bool AddNewVideo(string listType, string title, string description, string thumbnail, string videoid, string tags)
        {
            if (listType == "YouTube")
                return SharePoint.AddNewVideo("YouTubeVideos", title, description, thumbnail, videoid, tags);
            else
                return SharePoint.AddNewVideo("LocalVideos", title, description, thumbnail, videoid, tags);
        }
    }
}
